

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

//#include "print_log.h"

#define  nv_gw_msg_file_path   "./gw_msg.dat" 






#pragma pack(1)

typedef struct  {
  unsigned int lng;
  unsigned int lat;
  unsigned int tz;
  unsigned int ct;
  unsigned int vt;
}gw_param_cfg_t;


typedef struct {
	char swVer[16];
	char hwVer[16];
	char plcMac[16];
	char bleMac[16];
	char eth_mac[16];
	char wifi_mac[16];
	char masterId[32];
	char pid_gateway[32];
	char gatewayId[32];
	char panel_cnnttype[8];
	unsigned char sub_dev_linkmode;  // 子设备链接方式： 6：plc3921
	unsigned char netowrk_mode;      //  3：wifi，5：4G，7：eth
	unsigned char wiring_mode;     // 电表线
	unsigned char rsv;
	gw_param_cfg_t gw_param;
	
}nv_gw_msg_t;






//#if    SMART_ENABLE          

//----测试数据------

#define   USER_DATA_BUF_MAX     (256U)

typedef	 union 
{
		uint8_t  Buffer[USER_DATA_BUF_MAX];   //16*6+32*3+8+4+5*4=224
		struct         
		{					
			char swVer[16];
			char hwVer[16];
			char plcMac[16];
			char bleMac[16];
			char eth_mac[16];
			char wifi_mac[16];
			char masterId[32];
			char pid_gateway[32];
			char gatewayId[32];
			char panel_cnnttype[8];
			unsigned char sub_dev_linkmode;  // 子设备链接方式： 6：plc3921
			unsigned char netowrk_mode;      //  3：wifi，5：4G，7：eth
			unsigned char wiring_mode;     // 电表线
			unsigned char rsv;
			gw_param_cfg_t gw_param;
	
		} Reg;
	
}  nv_gw_msg_u;




#pragma pack()

  nv_gw_msg_u nv_gw_msg_obj;


unsigned int read_size_file(FILE *fp,long offset, uint8_t *pdst, int dst_size)
{
	fseek(fp, 0, SEEK_SET ); //SEEK_END
	return fread(pdst, 1, dst_size, fp);

}



void PrintHex( uint8_t *buf,uint16_t len)
{

#if   1   
		
uint16_t  i;

//打印到标准输出

	for (i = 0; i < len; i++)
	{
		printf("%02x ", buf[i]);
	}
	printf("\n");

	
#endif	
	
 
}



#if 0

int main(void )
{
FILE *fp=NULL;

char buf[1024];

   memset((char*) nv_gw_msg_obj.Buffer,0,sizeof(nv_gw_msg_u) );

    fp = fopen(nv_gw_msg_file_path,"r");  //以ASCII 编码方式打开  
  //   fp = fopen(nv_gw_msg_file_path,"rb");  //以二进制编码方式打开    
    if(fp != NULL) {

        printf("open file %s ok \n", nv_gw_msg_file_path );

        //read_total_file(fp, &gui_gw_param.nv_gw_msg, sizeof(nv_gw_msg_t));
      //  read_size_file(fp,0, &gui_gw_param.nv_gw_msg, sizeof(nv_gw_msg_t));

        read_size_file(fp,0, buf, sizeof(nv_gw_msg_t) ) ;


       PrintHex( buf,sizeof(nv_gw_msg_t) );
    // PrintHex2String( uint8_t *buf,uint16_t len);


       //memcpy( nv_gw_msg_obj.Buffer , buf, sizeof(nv_gw_msg_t) );

        read_size_file(fp,0, nv_gw_msg_obj.Buffer, sizeof(nv_gw_msg_u) ) ;
       PrintHex( nv_gw_msg_obj.Buffer,sizeof(nv_gw_msg_u)  );


        fclose(fp);

    }else{
        printf("open file %s fail \n", nv_gw_msg_file_path );

    }


   printf("gatewayId=%s\n", nv_gw_msg_obj.Reg.gatewayId );
   printf("plcMac=%s\n", nv_gw_msg_obj.Reg.plcMac );
   printf("eth_mac=%s\n", nv_gw_msg_obj.Reg.eth_mac );
   printf("masterId=%s\n", nv_gw_msg_obj.Reg.masterId );


   printf("hwVer=%s\n", nv_gw_msg_obj.Reg.hwVer );
   printf("swVer=%s\n", nv_gw_msg_obj.Reg.swVer );
   printf("pid_gateway=%s\n", nv_gw_msg_obj.Reg.pid_gateway );


   printf("ct=%d\n", nv_gw_msg_obj.Reg.gw_param.ct );
   printf("vt=%d\n", nv_gw_msg_obj.Reg.gw_param.vt );
   printf("tz=%d\n", nv_gw_msg_obj.Reg.gw_param.tz );
   printf("lat=%d\n", nv_gw_msg_obj.Reg.gw_param.lat );
   printf("lng=%d\n", nv_gw_msg_obj.Reg.gw_param.lng );


}

#endif

int main(void )
{
int32_t  cnt=0;
    while (1)
    {
		
          printf("helloworld %d\n\r", cnt);
          printf("strlen= %lu\n\r", strlen("csq="));//strlen= 4-----可见 strlen不包括 结束符

          sleep(7);//7sec 重新链接-------

	}

return 0;

}











//  gcc -o file_test file_test.c 
// riscv64-unknown-linux-gnu-gcc  -o file_test file_test.c 








